package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.content.model.dto.AddCourseTeacherDto;
import com.xuecheng.content.model.dto.EditCourseTeacherDto;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseTeacher")
@Api(value = "师资管理接口", tags = "师资管理接口")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @GetMapping("/list/{courseId}")
    @ApiOperation("查询教师信息")
    public List<CourseTeacher> listTeacherInfo(@PathVariable Long courseId) {
        return courseTeacherService.selectTeacherList(courseId);
    }

    @PostMapping
    @ApiOperation("添加教师信息")
    public CourseTeacher createTeacherInfo(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseTeacherDto addCourseTeacherDto) {
        // 获取到用户所属机构的id
        Long companyId = 1232141425L;
        return courseTeacherService.insertTeacherInfo(addCourseTeacherDto, companyId);
    }

    @PutMapping
    @ApiOperation("修改教师信息")
    public CourseTeacher modifyTeacherInfo(@RequestBody @Validated(ValidationGroups.Update.class) EditCourseTeacherDto editCourseTeacherDto) {
        // 获取到用户所属机构的id
        Long companyId = 1232141425L;
        return courseTeacherService.updateTeacherInfo(editCourseTeacherDto, companyId);
    }

    @DeleteMapping("/course/{courseId}/{courseTeacherId}")
    @ApiOperation("删除教师信息")
    public void deleteTeacherInfo(@PathVariable Long courseId,@PathVariable Long courseTeacherId) {
        // 获取到用户所属机构的id
        Long companyId = 1232141425L;
        courseTeacherService.deleteTeacherInfo(courseId, courseTeacherId, companyId);
    }
}
